package com.violet.common.util;

import com.violet.common.constant.universal.RegularExpressionConstant;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: wqf
 * @Date: 2023/07/21
 * @Description: 正则解析工具类
 */
public class RegexUtils {

    /**
     * 方法描述: 获取{}中的内容，如初始值{0} ==> 结果值0
     * 只能匹配单个{}中的值
     *
     * @param original 初始值
     * @return java.lang.String
     * @author wqf
     * @date 2023/7/21 9:49
     */
    public static String getCurlyBracketValue(String original) {
        Pattern pattern = Pattern.compile(RegularExpressionConstant.CURLY_BRACKET_REGEX);
        StringBuilder stringBuilder = new StringBuilder();
        Matcher matcher = pattern.matcher(original);
        while (matcher.find()) {
            String value = matcher.group(1);
            stringBuilder.append(value);
        }
        return stringBuilder.toString();
    }

    /**
     * 方法描述: 校验字符串整数是否为非负整数
     *
     * @param original 初始值
     * @return java.lang.String
     * @author wqf
     * @date 2023/7/21 10:02
     */
    public static boolean isNonNegativeNumber(String original) {
        return Pattern.matches(RegularExpressionConstant.NON_NEGATIVE_INTEGER, original);
    }

}
